package top.lingkang.securityoauth2.server;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.lingkang.securityoauth2.server.auth.ClientDetailService;
import top.lingkang.securityoauth2.server.auth.TokenGenerate;
import top.lingkang.securityoauth2.server.auth.UserDetailService;
import top.lingkang.securityoauth2.server.auth.impl.DefaultClientDetailService;
import top.lingkang.securityoauth2.server.auth.impl.DefaultTokenGenerate;
import top.lingkang.securityoauth2.server.auth.impl.DefaultUserDetailService;
import top.lingkang.securityoauth2.server.config.Oauth2ServerConfiguration;
import top.lingkang.securityoauth2.server.config.SecurityOauth2Server;
import top.lingkang.securityoauth2.server.controller.Oauth2ServerController;
import top.lingkang.securityoauth2.server.store.TokenStore;
import top.lingkang.securityoauth2.server.store.impl.RedisTokenStore;

/**
 * @author lingkang
 * Created by 2022/7/5
 */
@Configuration
public class AutoOauth2ServerConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public Oauth2ServerConfiguration oauth2ServerConfiguration() {
        return new Oauth2ServerConfiguration();
    }

    @Bean
    public Oauth2ServerController oauth2ServerController() {
        System.out.println("Oauth2ServerController loading ... ");
        return new Oauth2ServerController();
    }

    @Bean
    @ConditionalOnMissingBean
    public TokenStore tokenStore() {
        return new RedisTokenStore(null);
    }

    @Bean
    @ConditionalOnMissingBean
    public UserDetailService userDetailService() {
        return new DefaultUserDetailService();
    }

    @Bean
    @ConditionalOnMissingBean
    public ClientDetailService clientDetailService() {
        return new DefaultClientDetailService();
    }

    @Bean
    @ConditionalOnMissingBean
    public TokenGenerate TokenGenerate() {
        return new DefaultTokenGenerate();
    }

    @Bean
    @ConditionalOnMissingBean
    public SecurityOauth2Server securityOauth2Server() {
        return new SecurityOauth2Server();
    }
}
